package com.lingxu.module.collection.service.impl;


import com.lingxu.base.system.manage.vo.LoginUser;
import com.lingxu.module.collection.entity.ManageAnalysisSearchVo;
import com.lingxu.module.collection.entity.UserCountInfo;
import com.lingxu.module.collection.mapper.ManageAnalysisMapper;
import com.lingxu.module.collection.service.IManageAnalysisService;
import com.lingxu.module.homeIndex.entity.ParamsDTO;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ManageAnalysisService implements IManageAnalysisService {

    @Resource
    private ManageAnalysisMapper manageAnalysisMapper;

    @Override
    public List<UserCountInfo> getUserLoginInfo(ManageAnalysisSearchVo vo) {
        String region="";
        if(StringUtils.isBlank(vo.getRegion())){
            LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
            if(org.apache.commons.lang.StringUtils.isNotBlank(user.getRegion())){
                region= user.getRegion();
            }else{
                region="320000";
            }
        }else {
            region=vo.getRegion();
        }
        return manageAnalysisMapper.getUserLoginInfo(region);
    }

    @Override
    public List<UserCountInfo> getDataCountInfo(ManageAnalysisSearchVo vo) {
        String region="";
        if(StringUtils.isBlank(vo.getRegion())){
            LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
            if(org.apache.commons.lang.StringUtils.isNotBlank(user.getRegion())){
                region= user.getRegion();
            }else{
                region="320000";
            }
        }else {
            region=vo.getRegion();
        }
        return manageAnalysisMapper.getDataCountInfo(region);
    }

    @Override
    public List<UserCountInfo> getModelCountInfo(ParamsDTO dto) {
        if(StringUtils.isEmpty(dto.getAreaCode())){
            dto.setAreaCode("320800");
        }
        return manageAnalysisMapper.getModelCountInfo(dto);
    }

    @Override
    public List<UserCountInfo> getRedMaintenanceList(ManageAnalysisSearchVo vo) {
        String region="";
        if(StringUtils.isBlank(vo.getRegion())){
            LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
            if(org.apache.commons.lang.StringUtils.isNotBlank(user.getRegion())){
                region= user.getRegion();
            }else{
                region="320000";
            }
        }else {
            region=vo.getRegion();
        }
        return manageAnalysisMapper.getRedMaintenanceList(region);
    }

    @Override
    public List<UserCountInfo> getRedWarnList(ManageAnalysisSearchVo vo) {
        String region="";
        if(StringUtils.isBlank(vo.getRegion())){
            LoginUser user =  (LoginUser) SecurityUtils.getSubject().getPrincipal();
            if(org.apache.commons.lang.StringUtils.isNotBlank(user.getRegion())){
                region= user.getRegion();
            }else{
                region="320000";
            }
        }else {
            region=vo.getRegion();
        }
        return manageAnalysisMapper.getRedWarnList(region);
    }
}
